<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // ## 3.使用reduce实现数组去重
        var arr = [1,2,3,4,5,6,7,8,9,1,5,3,6,9,7,8,4,2,1,8,9,5,,1,2,5,8]
        
        var res = arr.reduce(function(pre,cur){
            //给pre 的状态为一个空数组，进行循环
            //循环判断pre这个数组有没有cur这个值
            //有的话继续循环
            //没有的话直接concat到新数组
            if(pre.indexOf(cur) === -1){
                return pre.concat(cur)
            }else{
                return pre
            }
        },[])
        console.log(res)
    </script>
</body>
</html>